package com.kitwee.serialport.decoder.mitsubishi;

import com.kitwee.serialport.decoder.InstructionDecoder;

/**
 * 三菱Q系列解码器
 * @author szhyde
 *
 */
public class QInstructionDecoder extends InstructionDecoder {

	@Override
	public  synchronized Object decode(byte[] source) {
		source = asciiTransformByte(new String(source).toCharArray());
		byte[] tempByte = new byte[source.length-11];
		System.arraycopy(source, 11, tempByte, 0, tempByte.length);
		
		byte[] temp = new byte[tempByte.length];
		int tempIndex = 0;
		for (int i = tempByte.length-1; i >= 0; i=i-2) {
			if(tempByte.length>(tempIndex)&&tempByte.length>1){
				temp[tempIndex++] = tempByte[i-1];
			}
			temp[tempIndex++] = tempByte[i];
		}

		if(byteArray2int(temp) > 1000000 ){
			throw new IllegalArgumentException("数据值异常");
		}
		return byteArray2int(temp);
		
	}
	
}
